<template>
  <el-dialog
    class="modify-class"
    width="95%"
    title="单机进度详情"
    visible
    :close-on-click-modal="false"
    :before-close="beforeClose"
  >
    <!-- popper-class="table-select-poppper" -->
    <el-form class="modify-form mt10" inline>
      <el-form-item label="分系统代号"
        ><span class="form-value">{{ detailData.sysCode }}</span></el-form-item
      >
      <el-form-item label="分系统名称" style="margin-left: 100px"
        ><span class="form-value">{{
          detailData.sysSubName
        }}</span></el-form-item
      >

      <div style="float:right">
        <el-form-item style="margin-bottom:0;padding-top: 2px;">
          <div class="s-input" style="margin-top: 5px;margin-right:0;">
            <input
              type="text"
              v-model="searchData.deviceNo"
              @keyup.enter="searchHandle"
              placeholder="出厂编号"
            />
            <img
              src="@/assets/images/search.png"
              alt="搜索按钮"
              @click="searchHandle"
            />
          </div>
        </el-form-item>
      </div>
    </el-form>

    <device-table :loading="loading" :list="tableData" @refresh="refresh"></device-table>
    <div style="padding: 10px;text-align: center;">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :page-size="pageOption.pageSize"
        :total="pageOption.total"
        :page-sizes="pageOption.sizes"
        @size-change="sizeCurrentChange"
        @current-change="pageCurrentChange"
      >
      </el-pagination>
    </div>
  </el-dialog>
</template>

<script>
import progressApi from "@/apis/overview/progress.js";
import DeviceTable from './table/DeviceTable'

export default {
  components: { DeviceTable },
  props: ["detailData"],
  data() {
    return {
      loading: false,
      tableData: [],
      searchData: {
        deviceCode: this.detailData ? this.detailData.deviceCode || '' : '',
        deviceNo: '',
        // deviceName: ''
      },
      pageOption: {
        page: 1,
        pageSize: 10,
        total: 0,
        sizes: [5, 10, 20, 30, 40, 50, 100]
      },
    };
  },
  watch: {
    detailData(val) {
      if(val) {
        this.searchData.deviceCode = val.deviceCode
      }
    }
  },
  methods: {
    beforeClose() {
      this.close();
    },
    close(refresh) {
      this.$emit("close", refresh || this.closeRefresh);
    },
    refresh() {
      this.closeRefresh = true
      this.requestListData()
    },
    searchHandle() {
      this.pageOption.page = 1
      this.requestListData()
    },
    sizeCurrentChange(size) {
      this.pageOption.pageSize = size
      this.requestListData()
    },
    pageCurrentChange(page) {
      this.pageOption.page = page
      this.requestListData()
    },
    requestListData() {
      const { modelId, sysCode, sysSubCode } = this.detailData;
      const {page, pageSize} = this.pageOption
      this.loading = true
      progressApi
        .progressDeviceFindPageInfo({
          modelId,
          sysCode,
          sysSubCode,
          ...this.searchData,
          pageNum: page,
          pageSize
        })
        .then(({ data }) => {
          const {list, total} = data
          this.tableData = list.map((item) => {
            item.edit = false;
            item.deviceNos =  item.deviceNo
            return item;
          });
          this.pageOption.total = total
          this.loading = false
        }).catch(() => {
          this.loading = false
        });
    }
  },
  mounted() {
    this.closeRefresh = false
    this.requestListData();
  },
};
</script>

<style lang="scss">
.form-value {
  color: #111434;
}
.cascader {
  .el-cascader-node {
    height: auto;
  }
}
.border-solid {
  padding: 10px;
  border: 1px solid #d8dcea;
}
</style>
